home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Utilities / Programming / CTools 2.2.1d / CTools / CTools.rsrc / TEXT_143_Formatting.txt < prev    next >
Encoding:
Text File  |  1995-12-01  |  4.5 KB  |  58 lines

  1. C Source Formatter:
  2.  
  3. The CTools‚Ñ¢ C source formatter works beautifully.  It only works on files suffixed in ‚Äú.c‚Äù though.  
  4.  
  5. The C source formatter will operate on a ‚ÄúCommand 1‚Äù key combination on the open file, whereupon it does it and replaces the ext in the file with the formatted text.  If you want to keep this, then close and save, or vice versa.  Otherwise you MUST select ‚ÄúSave As‚Äù from the file menu if you do not want your original source altered.
  6.  
  7. I have never had an error in its output as long as the input was compilable code and not too big.  Sometimes it will balk on a BIG¬†file, or one with some unusual weirdnesses.  But that‚Äôs very rare.  If it does do this, it will merely crash without eating your file (hopefully).  What I do, when I KNOW I have too big a file to format, is split it up.  Open the CTools‚Ñ¢ ‚ÄúWorkSheet.c‚Äù file, select half the file to be processed file, copy it, paste it into the worksheet, format it, select all, cut, save the worksheet, switch back to the intended file and paste and save.  Then select the other half.  You can do this between your editor and CTools‚Ñ¢ or all in CTools‚Ñ¢.
  8.  
  9. The formatter doubles as a ‚ÄúC check‚Äù function, in that if there is a missing brace or missing semicolon or missing paren, the Source Formatter output will have odd indents immediately afterward.  You can correct these glitches right in the CTools‚Ñ¢ window.  Scroll down until the code looks oddly indented, find the omission, add it, and run the formatter again.
  10.  
  11. If you have a missing ‚Äúcase‚Äù keyword before a ‚Äò:‚Äô then CTools‚Ñ¢ will not indent that line, so those are easy to find.
  12.  
  13. You can also paste a routine into a new CTools‚Ñ¢ document being used as a ‚Äúworksheet‚Äù and format it, then cut or copy it out.  The file must be ‚Äúsaved‚Äù with the ‚Äú.c‚Äù suffix in order for it to work.  But if you want to pump code and not deal with indents until you are done, then just have CTools‚Ñ¢ running in MultiFinder and, when you‚Äôre done typing, select all and copy, paste into your CTools‚Ñ¢ ‚Äúworksheet.c‚Äù, hit Command 1, select all and cut again, save the worksheet.c file (save empty) and then paste your source back into your code file.
  14.  
  15. One tip on big files, suppose you have a huge routine and CTools‚Ñ¢ doesn‚Äôt have enough ‚Äúpoop‚Äù to process it?  Simply:
  16.  
  17. ( 1) Move the insertion point to the top of the file in your code editor.
  18. ( 2) Drag the scroll thimb halfway down.
  19. ( 3) Hold SHIFT and click near the left margin.
  20. ( 4) Command V.
  21. ( 5) Switch to the CTools‚Ñ¢ Worksheet.c window.
  22. ( 6) Command 1.
  23. ( 7) Command A.
  24. ( 8) Command X.
  25. ( 9)Commad S.
  26. (10) Switch back to your editor.
  27. (11) Command V.  
  28.  
  29. Now, the tricky part...
  30.  
  31. You‚Äôll want the remaining, unformatted source from the file to have the same indent as the part it goes under IF you are mid-routine.  If you format the remainder the way it is, missing begin braces will result in mismatched indents.  So, do this:
  32.  
  33. ( 1) Put the insertion point just before the first character of the last 
  34.         line of the code you just formatted.
  35. ( 2) Hit the left arrow and count how many times you hit it to get the
  36.         insertion point to the left margin.
  37. ( 3) Hit the down arrow to get below that code.
  38. ( 4) Drag the scroll thumb to the bottom of the file.
  39. ( 5) Hold Shift and click past the end of all the code.
  40. ( 6) Command C.
  41. ( 7) Switch back to the CTools‚Ñ¢ Worksheet.c window.
  42. ( 8) Type the same number of begin braces as the number of left arrow hits 
  43.         you counted earlier.
  44. ( 9) Command V.
  45. (10) Command 1.
  46. (11) Command X.
  47. (12) Command S.
  48. (13) Switch back to your editor.
  49. (14) Command V.
  50.  
  51. I will be working in more user configurability but, until then, YOU have to do a little configuration on your own if you do not want your source to appear as CTools‚Ñ¢ puts it out - but not much.
  52.  
  53. If a brace is on the same line as an 'if' statement it will stay there.  If you want it on its own, new line, pre-edit by using a Find/Replace function in a text editor.  Find " {" (space leftBrace) and Replace All with "<cr>{" (return leftBrace) before running the formatter.  A Find/Replace function will be added to CTools‚Ñ¢, soon, so you can do this ‚Äúin-house‚Äù, but it will probably just be a part of the preferences.
  54.  
  55. If you want to see how good this formatter is, preprocess a small source file, replace all RETURNs with a space, save the result and run the formatter on it!  
  56.  
  57. If you intend to clean up CTools‚Ñ¢ output from the Pascal to C function, you MUST edit it so that it has ALL matching braces, parens and semicolons first.  The technique for doing this is detailed in the Pascal to C section.
  58.